widget: Store category of widget transform
authorBenjamin Otte <otte@redhat.com>
Tue, 19 Feb 2019 07:24:59 +0000 (08:24 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 21 Feb 2019 18:47:28 +0000 (19:47 +0100)
And pass that category through to the transform node that we create for
it.

gtk/gtksnapshot.c
gtk/gtksnapshotprivate.h
gtk/gtkwidget.c
gtk/gtkwidgetprivate.h

index 3f7f10060824b2b9add6f620a535c5206d7b33b5..2d31929d8a3e8edce28628458cd3c1e9e94827f1 100644 (file)
@@ -296,7 +296,9 @@ gtk_snapshot_collect_transform (GtkSnapshot      *snapshot,
   if (node == NULL)
     return NULL;
 
-  transform_node = gsk_transform_node_new (node, &state->data.transform.transform);
+  transform_node = gsk_transform_node_new_with_category (node,
+                                                         &state->data.transform.transform,
+                                                         state->data.transform.category);
 
   gsk_render_node_unref (node);
 
@@ -306,6 +308,16 @@ gtk_snapshot_collect_transform (GtkSnapshot      *snapshot,
 void
 gtk_snapshot_push_transform (GtkSnapshot             *snapshot,
                              const graphene_matrix_t *transform)
+{
+  gtk_snapshot_push_transform_with_category (snapshot,
+                                             transform,
+                                             GSK_MATRIX_CATEGORY_UNKNOWN);
+}
+
+void
+gtk_snapshot_push_transform_with_category (GtkSnapshot             *snapshot,
+                                           const graphene_matrix_t *transform,
+                                           GskMatrixCategory        category)
 {
   GtkSnapshotState *previous_state;
   GtkSnapshotState *state;
@@ -325,6 +337,10 @@ gtk_snapshot_push_transform (GtkSnapshot             *snapshot,
                                   ));
 
   graphene_matrix_multiply (transform, &offset, &state->data.transform.transform);
+  if (previous_state->translate_x || previous_state->translate_y)
+    state->data.transform.category = MIN (GSK_MATRIX_CATEGORY_2D_TRANSLATE, category);
+  else
+    state->data.transform.category = category;
 }
 
 static GskRenderNode *
index 5e554ca85ec1b5156ac61bc9a172ee80555dff5e..b03205d5cd99c2826dbb1380f36c580faf7aafb4 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "gtksnapshot.h"
 
+#include "gsk/gskrendernodeprivate.h"
+
 G_BEGIN_DECLS
 
 typedef struct _GtkSnapshotState GtkSnapshotState;
@@ -40,6 +42,7 @@ struct _GtkSnapshotState {
   union {
     struct {
       graphene_matrix_t transform;
+      GskMatrixCategory category;
     } transform;
     struct {
       double            opacity;
@@ -103,6 +106,9 @@ void                    gtk_snapshot_append_node_internal       (GtkSnapshot
 
 GtkSnapshot *           gtk_snapshot_new_with_parent            (GtkSnapshot            *parent_snapshot);
 
+void                    gtk_snapshot_push_transform_with_category (GtkSnapshot          *snapshot,
+                                                                 const graphene_matrix_t*transform,
+                                                                 GskMatrixCategory       category);
 G_END_DECLS
 
 #endif /* __GTK_SNAPSHOT_PRIVATE_H__ */
index a0f5a5d72cede308a16e9041debaa51907515f10..feecd3774eda6bbe9ab4cde31ce4d4cedd48f2f2 100644 (file)
@@ -61,7 +61,7 @@
 #include "gtksnapshotprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "gtktooltipprivate.h"
-#include "gtktransform.h"
+#include "gtktransformprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkversion.h"
 #include "gtkwidgetpaintableprivate.h"
@@ -4348,6 +4348,9 @@ gtk_widget_allocate (GtkWidget    *widget,
   graphene_matrix_init_translate (&priv->transform, &GRAPHENE_POINT3D_INIT (adjusted.x, adjusted.y, 0));
   gtk_transform_to_matrix (transform, &transform_matrix);
   graphene_matrix_multiply (&priv->transform, &transform_matrix, &priv->transform);
+  priv->transform_category = gtk_transform_categorize (transform);
+  if (adjusted.x || adjusted.y)
+    priv->transform_category = MIN (priv->transform_category, GSK_MATRIX_CATEGORY_2D_TRANSLATE);
 
   if (!alloc_needed && !size_changed && !baseline_changed)
     {
@@ -13511,20 +13514,15 @@ gtk_widget_snapshot_child (GtkWidget   *widget,
                            GtkSnapshot *snapshot)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (child);
-  gboolean needs_transform;
 
   g_return_if_fail (_gtk_widget_get_parent (child) == widget);
   g_return_if_fail (snapshot != NULL);
 
-  needs_transform = !graphene_matrix_is_identity (&priv->transform);
-
-  if (needs_transform)
-    gtk_snapshot_push_transform (snapshot, &priv->transform);
+  gtk_snapshot_push_transform_with_category (snapshot, &priv->transform, priv->transform_category);
 
   gtk_widget_snapshot (child, snapshot);
 
-  if (needs_transform)
-    gtk_snapshot_pop (snapshot);
+  gtk_snapshot_pop (snapshot);
 }
 
 /**
index 8b1e672a87ee34fe0e11387d8c8e3282b781e8dc..8b4bf94e676cab871a523b9f01aefde910688bf8 100644 (file)
@@ -38,6 +38,8 @@
 #include "gtkinvisibleprivate.h"
 #include "gtkgesture.h"
 
+#include "gsk/gskrendernodeprivate.h"
+
 G_BEGIN_DECLS
 
 #define GTK_STATE_FLAGS_BITS 14
@@ -150,6 +152,7 @@ struct _GtkWidgetPrivate
   gint allocated_size_baseline;
 
   graphene_matrix_t transform;
+  GskMatrixCategory transform_category;
   int width;
   int height;
   int baseline;